define(function(require,exports,module){
	var aw = require("ajaxwrapper");
	var Dialog = require("dialog");
	var Grid = require("grid");
	
    module.exports = {
    		showDetail:function(widget, data){
    			if(data.money == "0.00"){
    				Dialog.alert({
    					tip:"提示！",
    					content:"没有该类消费！"
    				});
    				return false;
    			}
    			var roomPerData = widget.get("roomPerData");
    			// 房间消费
    			if(data.key == "roomConsumption"){
    				var consumptionData = roomPerData.roomPerConsumptions;
    				var roomConsumption = [];
    				for(var i=0; i < consumptionData.length; i++){
    					if(consumptionData[i].consumptionType.key == "RoomConsumption"){
    						consumptionData[i].sum = consumptionData[i].price*consumptionData[i].num;
    						roomConsumption.push(consumptionData[i]);
    					}
    				}
    				var conSumpGrid = this.conSumpGrid();
    				conSumpGrid.setData(roomConsumption);
    				Dialog.showComponent(conSumpGrid,{ 
    					title : "房间消费清单",
    					defaultButton : false,
    					buttons : [{
                            id : "return",
                            text : "关闭",
                            handler : function(){
                            	Dialog.close();
                            }
                        }],
    					setStyle:this.setStyle
    				});
    			}
    			// 赔偿费
    			if(data.key == "damages"){
    				var consumptionData = roomPerData.roomPerConsumptions;
    				var damageConsumption = [];
    				for(var i=0; i < consumptionData.length; i++){
    					if(consumptionData[i].consumptionType.key == "DamageConsumption"){
    						consumptionData[i].sum = consumptionData[i].price*consumptionData[i].num;
    						damageConsumption.push(consumptionData[i]);
    					}
    				}
    				var conSumpGrid = this.conSumpGrid();
    				conSumpGrid.setData(damageConsumption);
    				Dialog.showComponent(conSumpGrid,{ 
    					title : "房间赔偿清单",
    					defaultButton : false,
    					buttons : [{
                            id : "return",
                            text : "关闭",
                            handler : function(){
                            	Dialog.close();
                            }
                        }],
    					setStyle:this.setStyle
    				});
    			}
    			// 电费
    			
    			var basePrice = widget.get("basePrice");
    			if(data.key == "electric"){
    				var that = this;
					var electricMeter = roomPerData.roomRegister.electricMeter;
					var checkOutElectricMeter = roomPerData.roomRegister.checkOutElectricMeter;
					var datas = [{
						inMeter:electricMeter,
						outMeter:checkOutElectricMeter,
						useNum:checkOutElectricMeter-electricMeter,
						price:basePrice.electric,
						sum:basePrice.electric*(checkOutElectricMeter-electricMeter)
					}];
					var electricWaterGrid = that.electricWaterGrid("用电量");
					electricWaterGrid.setData(datas);
    				Dialog.showComponent(electricWaterGrid,{ 
    					title : "电费",
    					defaultButton : false,
    					buttons : [{
                            id : "return",
                            text : "关闭",
                            handler : function(){
                            	Dialog.close();
                            }
                        }],
    					setStyle:that.setStyle
    				});
    			}
    			// 冷水费
    			if(data.key == "coldWater"){
    				var that = this;
					var waterMeter = roomPerData.roomRegister.waterMeter;
					var checkOutWaterMeter = roomPerData.roomRegister.checkOutWaterMeter;
					var datas = [{
						inMeter:waterMeter,
						outMeter:checkOutWaterMeter,
						useNum:checkOutWaterMeter-waterMeter,
						price:basePrice.water,
						sum:basePrice.water*(checkOutWaterMeter-waterMeter)
					}];
					var electricWaterGrid = that.electricWaterGrid("用水量");
					electricWaterGrid.setData(datas);
    				Dialog.showComponent(electricWaterGrid,{ 
    					title : "冷水费",
    					defaultButton : false,
    					buttons : [{
                            id : "return",
                            text : "关闭",
                            handler : function(){
                            	Dialog.close();
                            }
                        }],
    					setStyle:that.setStyle
    				});
    			}
    			// 热水费
    			if(data.key == "hotWater"){
    				var that = this;
					var hotWaterMeter = roomPerData.roomRegister.hotWaterMeter;
					var checkOutHotWaterMeter = roomPerData.roomRegister.checkOutHotWaterMeter;
					var datas = [{
						inMeter:hotWaterMeter,
						outMeter:checkOutHotWaterMeter,
						useNum:checkOutHotWaterMeter-hotWaterMeter,
						price:basePrice.hotWater,
						sum:basePrice.hotWater*(checkOutHotWaterMeter-hotWaterMeter)
					}];
					var electricWaterGrid = that.electricWaterGrid("用水量");
					electricWaterGrid.setData(datas);
    				Dialog.showComponent(electricWaterGrid,{ 
    					title : "热水费",
    					defaultButton : false,
    					buttons : [{
                            id : "return",
                            text : "关闭",
                            handler : function(){
                            	Dialog.close();
                            }
                        }],
    					setStyle:that.setStyle
    				});
    			}
    		},
    		
    		// 初始化房间消费，赔偿费列表
    		conSumpGrid: function(){
    			return new Grid({
    	       		 	isInitPageBar:false,
    	                model:{
    	                    columns:[{
    	                        key:"goods.name",
    	                        name:"物品名称"
    	                    },{
    	                    	key:"price",
    	                    	name:"单价（元）"
    	                    },{
    							key:"num",
    							name:"数量"
    						},{
    							key:"sum",
    							name:"总金额（元）"
    						},{
    							key:"description",
    							name:"备注"
    						}]
    					}
    			});
    		},
    		
    		// 初始化水电费列表
    		electricWaterGrid: function(str){
    			return new Grid({
	       		 	isInitPageBar:false,
	                model:{
	                    columns:[{
	                        key:"inMeter",
	                        name:"入住抄表值"
	                    },{
	                    	key:"outMeter",
	                    	name:"退住抄表值"
	                    },{
							key:"useNum",
							name:str
						},{
							key:"price",
							name:"单价(元)"
						},{
							key:"sum",
							name:"总金额（元）"
						}]
					}
    			});
    		},
    		setStyle:function(){
				$(".modal").css({
					"overflow": "visible",
					"height":" 472px",
				    "width": "50%",
					"margin-left":" -12%",
					"top":" 15%",
				});
				$(".modal-body").css({
					"overflow": "overlay",
					"height":" 350px",
				});
			}
    };
});
